﻿using AutoMapper;
using Common.Domain;
using Common.Infrastructure.Repository;
using Common.Services;
using MediatR;
using System.Data;

namespace Business.WriteAPI.Application.Products
{
    public class ProductUpdRequestHandler : IRequestHandler<ProductUpdRequestModel, APIResult>
    {
        private IBaseRepository<Product> productRepository;
        private readonly IMapper mapper;
        public ProductUpdRequestHandler(IBaseRepository<Product> productRepository, IMapper mapper)
        {
            this.productRepository = productRepository;
            this.mapper = mapper;
        }
        public Task<APIResult> Handle(ProductUpdRequestModel request, CancellationToken cancellationToken)
        {
            APIResult result = new APIResult();
            result.Code = EnumCode.UpdSuccess;
            result.Msg = "编辑成功";

            Product role = mapper.Map<Product>(request);
            productRepository.Update(role);

            return Task.FromResult(result);
        }
    }
    public class ProductUpdRequestModel:IRequest<APIResult>
    {
        public int ProductId { get; set; }
        public string ProductCode { get; set; }
        public int FoodId { get; set; }
        public string ProductionBatch { get; set; }
        public int ShelfLife { get; set; }
        public string LicenseNumber { get; set; }
        public string Enterprise { get; set; }
        public string Creator { get; set; }
        public DateTime CreateTime { get; set; } = DateTime.Now;
        public string Updator { get; set; }
        public DateTime UpdateTime { get; set; } = DateTime.Now;
        public string Deletor { get; set; }
        public DateTime DeleteTime { get; set; } = DateTime.Now;
        public string PhotoUrl { get; set; }
    }
}
